package tetris.agent;

import tetris.features.featureutils;
import tetris.simulator.State;


public class Agent {

	//implement this function to have a working system
	//Inputs:
	//- s is the current state of the board
	//- legalMoves is a nx2 matrix of the n possible actions for the current piece.
	//	An action is the orientation & column to place the current piece
	//Outputs:
	//- index n of the action to execute in legalMoves
	public int chooseAction(State s, int[][] legalMoves) 
	{		
		//example random agent
		
		//return random action
		return (int)(Math.random()*legalMoves.length); 
	}
	
	public int chooseAction_WtsFts(State s, double[]wt ) 
	{		

		int[][] legalMoves = s.legalMoves();
		double[] evalVal = new double[wt.length];
		double maxEvalVal = 0.0;
		int maxActInd = 0;
		for (int i=0; i<legalMoves.length;i++){
			featureutils fts = new featureutils();
			double[] allFeatures = fts.features(s, i);
			
			// find w'F
			evalVal[i] = multiVariateGaussian.dotProduct(allFeatures, wt);
			
			// find action with max w'F
			if (Math.abs(evalVal[i])>Math.abs(maxEvalVal)){
				maxEvalVal = evalVal[i];
				maxActInd = i;
			}
			
		}
		return maxActInd; 
	}
	
	
	
}
